package binarysearch.test287;

import java.util.HashSet;

/**
 * 寻找重复数
 * @author code_yc
 * @version 1.0
 * @date 2020/7/11 12:15
 */
public class Solution1 {

    public int findDuplicate(int[] nums) {
        int n = nums.length;
        int a = nums[0];
        int b = nums[nums[0]];
        while (a != b) {
            a = nums[a];
            b = nums[nums[b]];
        }
        a = 0;
        while (a != b) {
            a = nums[a];
            b = nums[b];
        }
        return a;
    }

}
